// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   WidthIVL_TSImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.GTS;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.IVL_TS;
import com.sunwayhorizo.health.hl7.datatypes.PQ;
import com.sunwayhorizo.health.hl7.datatypes.TS;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            IVL_TSImpl, ANYImpl, BLImpl, GTSBase, 
//            INTImpl, NullFlavorImpl, REALImpl, STImpl

public class WidthIVL_TSImpl extends IVL_TSImpl
    implements IVL_TS
{

    public static final String RCS_ID = "$Header: WidthIVL_TSImpl.java 115.14.2050.4 2006/02/22 05:18:52 mmoores noship $";
    protected PQ _width;

    public static WidthIVL_TSImpl valueOf(BL bl, PQ pq, BL bl1)
    {
        return new WidthIVL_TSImpl(bl, pq, bl1);
    }

    public static WidthIVL_TSImpl valueOf(TS ts, IVL_TS ivl_ts)
    {
        return new WidthIVL_TSImpl(ts, ivl_ts);
    }

    protected WidthIVL_TSImpl(TS ts, IVL_TS ivl_ts)
    {
        super(ivl_ts.lowClosed(), ivl_ts.highClosed());
        _center = ts;
        _width = (PQ)ivl_ts.width();
        com.sunwayhorizo.health.hl7.datatypes.REAL real = REALImpl.valueOf("0.5");
        PQ pq = _width.times(real);
        _low = (TS)ts.minus(pq);
        _high = (TS)ts.plus(pq);
        _literal = STImpl.valueOf(ts.literal().stringValue() + (lowClosed().isFalse() ? "]" : "[") + _width.literal().stringValue() + (highClosed().isFalse() ? "[" : "]"));
    }

    protected WidthIVL_TSImpl(BL bl, PQ pq, BL bl1)
    {
        super(bl, bl1);
        _width = pq;
        _literal = STImpl.valueOf((lowClosed().isFalse() ? "]" : "[") + pq.literal().stringValue() + (highClosed().isFalse() ? "[" : "]"));
    }

    public TS low()
    {
        return _low;
    }

    public TS high()
    {
        return _high;
    }

    public PQ width()
    {
        return _width;
    }

    public TS center()
    {
        return _center;
    }

    public BL contains(TS ts)
    {
        throw ANYImpl.newUnsupportedException("IVL<TS>", "contains");
    }

    public INT cardinality()
    {
        return INTImpl.nullINT(NullFlavorImpl.NA);
    }

    public IVL_TS intersection(IVL_TS ivl_ts)
    {
        if(_center.isNull().isTrue())
            return IVL_TSImpl.nullIVL_TS(NullFlavorImpl.NA);
        else
            return super.intersection(ivl_ts);
    }

    public IVL_TS hull(IVL_TS ivl_ts)
    {
        if(_center.isNull().isTrue())
            return IVL_TSImpl.nullIVL_TS(NullFlavorImpl.NA);
        else
            return super.hull(ivl_ts);
    }

    public IVL_TS hull()
    {
        return this;
    }

    public BL interleaves(GTS gts)
    {
        return BLImpl.FALSE;
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof IVL_TS))
            return BLImpl.FALSE;
        if(isNull().or(any.isNull()).isTrue())
        {
            return BLImpl.FALSE;
        } else
        {
            IVL_TS ivl_ts = (IVL_TS)any;
            return lowClosed().equal(ivl_ts.lowClosed()).and(highClosed().equal(ivl_ts.highClosed())).and(low().equal(ivl_ts.low())).and(high().equal(ivl_ts.high()));
        }
    }

    public TS demotion()
    {
        return center();
    }
}
